package com.xuecheng.media.service;

import com.xuecheng.base.model.PageParams;
import com.xuecheng.base.model.PageResult;
import com.xuecheng.base.model.RestResponse;
import com.xuecheng.media.model.dto.QueryMediaParamsDto;
import com.xuecheng.media.model.dto.UploadFileParamsDto;
import com.xuecheng.media.model.dto.UploadFileResultDto;
import com.xuecheng.media.model.po.MediaFiles;
import org.springframework.web.bind.annotation.RequestBody;

import java.io.File;
import java.util.List;

/**
 * @description 媒资文件管理业务类
 * @author Mr.M
 * @date 2022/9/10 8:55
 * @version 1.0
 */
public interface MediaFileService {

    /**
     * @description: 根据媒资id查询文件信息
     * @params: [mediaId]
     * @return:
     * @author: ajie
     * @date: 2024/1/25 16:52
     */
    public MediaFiles getFileById(String mediaId);

    /**
     * @description 媒资文件查询方法
     * @param pageParams 分页参数
     * @param queryMediaParamsDto 查询条件
     * @return com.xuecheng.base.model.PageResult<com.xuecheng.media.model.po.MediaFiles>
     * @author Mr.M
     * @date 2022/9/10 8:57
     */
    public PageResult<MediaFiles> queryMediaFiels(Long companyId, PageParams pageParams, QueryMediaParamsDto queryMediaParamsDto);

    /**
     * @description: 上传文件
     * @params:
     * [companyId 机构id,
     * uploadFileParamsDto 文件信息,
     * localFilePath  文件件本地路径
     * objectName    如果传入objectName要按objectName的目录去存储，如果不传就按年月日目录结构去存储]
     * @return: UploadFileResultDto
     * @author: ajie
     * @date: 2024/1/18 20:00
     */
    public UploadFileResultDto uploadFile(Long companyId, UploadFileParamsDto uploadFileParamsDto, String localFilePath,String objectName);

    /**
     * @description: 为了实现类的代理对象而暴露的接口，为了缩短事务控制
     * @params: [companyId, fileMd5, uploadFileParamsDto, bucketMediafiles, objectName]       
     * @return: 
     * @author: ajie
     * @date: 2024/1/19 17:21
     */
    public MediaFiles addMediaFilesToDb(Long companyId, String fileMd5, UploadFileParamsDto uploadFileParamsDto, String bucketMediafiles, String objectName);

    /**
     * @description: 检查文件是否存在
     * @params: [fileMd5]
     * @return:
     * @author: ajie
     * @date: 2024/1/19 21:35
     */
    public RestResponse<Boolean> checkfile(String fileMd5);

    /**
     * @description: 检查分块是否存在
     * @params: [fileMd5, chunk]
     * @return:
     * @author: ajie
     * @date: 2024/1/19 21:36
     */
    public RestResponse<Boolean> checkchunk(String fileMd5, int chunkIndex);
    
    /**
     * @description: 上传分块 
     * @params: [fileMd5, chunk, localChunkFilePath]       
     * @return: 
     * @author: ajie
     * @date: 2024/1/19 22:38
     */
    public RestResponse uploadChunk(String fileMd5,int chunk,String localChunkFilePath);

    /**
     * @description: 分块合并 
     * @params: [companyId, fileMd5, chunkTotal, uploadFileParamsDto]       
     * @return: 
     * @author: ajie
     * @date: 2024/1/20 19:38
     */
    public RestResponse mergechunks(Long companyId,String fileMd5,int chunkTotal,UploadFileParamsDto uploadFileParamsDto);

    /**
     * @description: 从minio下载文件
     * @params: [bucket, objectName]
     * @return:
     * @author: ajie
     * @date: 2024/1/20 12:27
     */
    public File downloadFileFromMinio(String bucket, String objectName);

    /**
     * @description: 将文件写入minio
     * @params: [localFilePath, mimeType 媒体类型, bucket, objectName]
     * @return:
     * @author: ajie
     * @date: 2024/1/18 20:32
     */
    public boolean addMediaFilesToMinIO(String localFilePath, String mimeType, String bucket, String objectName);
}
